package com.xbb.kafka.partitioner;

import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;

import java.util.Map;

public class MyPartitioner implements Partitioner {

  @Override
  public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {

    Integer integer = cluster.partitionCountForTopic(topic);


    return key.toString().hashCode() % integer;
    // return 1;
  }

  /**
   * This is called when partitioner is closed.
   */
  @Override
  public void close() {

  }

  /**
   * Configure this class with the given key-value pairs
   *
   * @param configs
   */
  @Override
  public void configure(Map<String, ?> configs) {

  }
}
